<?php
/**
* file encoding utf-8
* 文件字符編碼utf-8
*/
$PathToRongFramework = dirname(__FILE__)."/../lib"; //指向 名字為“Rong”的文件夾的父目錄。
set_include_path( "." . PATH_SEPARATOR . $PathToRongFramework . PATH_SEPARATOR . get_include_path() );
require_once 'Rong/Db.php';
require_once "Rong/Html/PageLink.php";
$db = Rong_Db::factory("Mysql", array(
"host" => "localhost", //mysql 主機
"username" => "root", //用户名
"password" => "123456", //密碼
"dbname" => "rong_db", //數據庫名稱
"charset" => "utf8" //字符集,也可以是gbk gb2312 ansii等
));
$page = intval( @$_GET["page"] ); //當前頁碼
$pageSize = 2; //頁面大小
$urlTemplate = "db_paginator.php?page={Page}&size={PageSize}"; //分頁鏈接的模板,“{Page}”表示頁碼,“{PageSize}”表示分頁大小。
$sql = "select * from w_article"; //要分頁的sql
$rs = $db->getPaginator($sql, $page, $pageSize, $urlTemplate ); //執行分頁
//輸出分頁的數據
echo "<table border=1>";
echo "<tr> <th>編號</th> <th>標題</th> <th>內容</th> <th>添加時間</th> </tr>";
for( $i=0; $i< count($rs["Data"]); $i++ )
{
$row = $rs["Data"][$i];
echo "<tr>";
echo "<td>" . $row["id"] . "</td>";
echo "<td>" . $row["title"] . "</td>";
echo "<td>" . $row["content"] . "</td>";
echo "<td>" . $row["add_time"] . "</td>";
echo "</tr>";
}
echo "</table>";
//輸出分類的鏈接
echo $rs["PaginatorHtml"];
echo "<h3>分頁時返回的數據</h3>";
echo "<pre>";
print_r( $rs );
echo "</pre>";
我們期待收到您的消息